<?php

namespace App\Http\Resources\Api;

use App\Support\ResourceCollection;

class Categories extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return $this->collection->map([$this, 'item'])->all();
    }

    /**
     * 格式化单个数据
     *
     * @param \Modules\Xiaoyu\Models\Banner $item
     * @return array
     */
    public function item($item)
    {
        if ($item->goods) {
            foreach ($item->goods as &$goods) {
                $goods->full_image = image_url($goods->image);
            }
        }
        return $item;
    }
}
